<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>新建采购合同模板</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">

        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits">
                        <span>基本信息</span>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>模板标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="yangname" id="yangname" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">模板说明</label>
                        <div class="layui-input-block">
                            <input type="text" name="yangshuo" id="yangshuo" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" readonly autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">合同名称</label>
                        <div class="layui-input-block">
                            <input type="text" readonly autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">合同状态</label>
                        <div class="layui-input-block">
                            <select id="state" name="state" lay-filter="state" ></select>
                            <p class="error" id="state_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">合同编号</label>
                        <div class="layui-input-block">
                            <input type="text" readonly autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">合同年份</label>
                        <div class="layui-input-block">
                            <select id="year" name="year" lay-filter="year" ></select>
                            <p class="error" id="year_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">合同类型</label>
                        <div class="layui-input-block">
                            <select id="caihetype" name="caihetype" lay-filter="caihetype"></select>
                            <p class="error" id="caihetype_error" style="margin: 0;"></p>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">合同属性</label>
                        <div class="layui-input-block">
                            <div id="caiheshu"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">供应方(乙方)</label>
                        <div class="layui-input-block">
                            <input type="text" readonly autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">采购方(甲方)</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=caier&type=dept&dept=chan&single=1','770px','490px');"></div>
                                <div class="tanxiannei" id="caier"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=caier&type=dept&dept=chan&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="caier_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">乙方联系人</label>
                        <div class="layui-input-block">
                            <input type="text" readonly autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">我方签订人</label>
                        <div class="layui-input-block">
                            <input type="text" name="myer" id="myer" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">乙方联系方式</label>
                        <div class="layui-input-block">
                            <input type="text" readonly autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">签订日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="qiandt" id="qiandt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">合同金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" readonly autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">税率(%)</label>
                        <div class="layui-input-block">
                            <input type="number" name="rate" id="rate" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">合同开始日期</label>
                        <div class="layui-input-block">
                            <input type="text" readonly autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">合同结束日期</label>
                        <div class="layui-input-block">
                            <input type="text" readonly autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">质保金比例(%)</label>
                        <div class="layui-input-block">
                            <input type="number" name="zhirate" id="zhirate" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">质保金金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" readonly autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">结算方式</label>
                        <div class="layui-input-block">
                            <textarea id="settle" name="settle" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">支付条件</label>
                        <div class="layui-input-block">
                            <textarea id="zhitiao" name="zhitiao" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">主要条款</label>
                        <div class="layui-input-block">
                            <textarea id="clause" name="clause" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">违约责任</label>
                        <div class="layui-input-block">
                            <textarea id="viola" name="viola" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
        </div>


    </div>
</form>
<script>

    var param_caiid = getQueryVariable('caiid') || 0;

    $("#commentForm").validate({
        rules: {
            yangname: {required: true},
        },
        messages:{
            yangname: {required: "请输入"},
        }
    });

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_contract_yang_add,data:{caiid:param_caiid}}).done(function(res){
            if (res.code === 2000) {

                var data = res.data.caiinfo || '';
                if(data){
                    $("#yangname").val(data.yangname);
                    $("#yangshuo").val(data.yangshuo);
                    $("#myer").val(data.myer);
                    $("#qiandt").val(data.qiandt);
                    $("#rate").val(data.rate);
                    $("#startdt").val(data.startdt);
                    $("#enddt").val(data.enddt);
                    $("#zhirate").val(data.zhirate);
                    $("#settle").val(data.settle);
                    $("#zhitiao").val(data.zhitiao);
                    $("#clause").val(data.clause);
                    $("#viola").val(data.viola);


                    if(data.caier_info.length > 0){
                        tan_tags_init('#caier', data.caier_info);
                    }

                    var state_str = '<option value="">请选择</option>';
                    var state = res.data.state;
                    for (var key in state){
                        if(data.state == key){
                            state_str += '<option value="'+key+'" selected>'+state[key]+'</option>';
                        }else{
                            state_str += '<option value="'+key+'">'+state[key]+'</option>';
                        }
                    }
                    $("#state").html(state_str);

                    var year_str = '<option value="">请选择</option>';
                    var year = res.data.year;
                    for (var key in year){
                        if(data.year == year[key]){
                            year_str += '<option value="'+year[key]+'" selected>'+year[key]+'</option>';
                        }else{
                            year_str += '<option value="'+year[key]+'">'+year[key]+'</option>';
                        }
                    }
                    $("#year").html(year_str);

                    var caihetype_str = '<option value="">请选择</option>';
                    var caihetype = res.data.caihetype;
                    for (var key in caihetype){
                        if(data.caihetype == key){
                            caihetype_str += '<option value="'+key+'" selected>'+caihetype[key]+'</option>';
                        }else{
                            caihetype_str += '<option value="'+key+'">'+caihetype[key]+'</option>';
                        }
                    }
                    $("#caihetype").html(caihetype_str);

                    xmselect_dan('caiheshu', res.data.caiheshu, data.caiheshu);
                }else{
                    var state_str = '<option value="">请选择</option>';
                    var state = res.data.state;
                    for (var key in state){
                        state_str += '<option value="'+key+'">'+state[key]+'</option>';
                    }
                    $("#state").html(state_str);

                    var year_str = '<option value="">请选择</option>';
                    var year = res.data.year;
                    for (var key in year){
                        year_str += '<option value="'+year[key]+'">'+year[key]+'</option>';
                    }
                    $("#year").html(year_str);

                    var caihetype_str = '<option value="">请选择</option>';
                    var caihetype = res.data.caihetype;
                    for (var key in caihetype){
                        caihetype_str += '<option value="'+key+'">'+caihetype[key]+'</option>';
                    }
                    $("#caihetype").html(caihetype_str);

                    xmselect_dan('caiheshu', res.data.caiheshu, '');
                }




                render_from();
            }
        });

        form.on('submit(add)', function(data){
            var validRes = $("#commentForm").valid();
            data.field.caier = tan_tags_getvalue("#caier", 'dept');
            if(!validRes){return false;}

            facade.ajax({url: ask_contract_yang_add, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });

</script>
</body>
</html>
